﻿@{
    Layout = "~/Views/Shared/ShouYe.cshtml";
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>zhuce</title>
    <link href="~/Content/css/bootstrap.min.css" rel="stylesheet" />
    <script src="~/Scripts/js/jquery.min.js"></script>
    <script src="~/Scripts/js/bootstrap.min.js"></script>
    <script src="~/Scripts/jquery-1.8.2.min.js"></script>
</head>
<body>
    <div class="col-lg-12">
        <div class="col-lg-6">
            <table class="tab-content table table-bordered table-striped table-responsive" style="margin-left:45%;">
                <tr>
                    <td colspan="2" style="text-align:center">
                        <h2>请输入用户基本信息</h2>
                    </td>
                </tr>
                <tr>
                    <td>用户名：</td>
                    <td><input id="yonghu" type="text" onblur="yonghus()" />
                        <span id="spanyonghu" style="color:#1653f1"></span>
                    </td>
                </tr>
                <tr>
                    <td>密码：</td>
                    <td>
                        <input id="mima" type="password" onblur="pass()" onfocus="emailyz()" />
                        <span id="spanpass" style="color:#e2d416"></span>
                    </td>
                </tr>
                <tr>
                    <td>确认密码：</td>
                    <td>
                        <input id="tmima" type="password" onblur="pass2()" />
                        <span id="spantwo" style="color:#d3f00c"></span>
                    </td>
                </tr>
                <tr>
                    <td>手机号：</td>
                    <td>
                        <input id="shouji" type="text" onblur="phone()" />
                        <span id="spanphone" style="color:#55931c"></span>
</td>
                </tr>
                <tr>
                    <td>邮箱：</td>
                    <td><input id="youxiang" type="email" value="" onblur="email()" />
                        
                        <span id="spanadd" style="color:red"></span>
                    </td>
                </tr>
                <tr>
                    <td>真实姓名：</td>
                    <td>
                        <input id="name" type="text" onblur="mingzi()" />
                        <span id="spanname" style="color:#1653f1"></span>
                    </td>
                </tr>
                <tr>
                    <td>性别：</td>
                    <td>
                        <input id="Radio1" name="sex" type="radio" value="男" />男
                        <input id="Radio1" name="sex" type="radio" value="女" />女
                    </td>
                </tr>
                <tr>
                    <td>年龄：</td>
                    <td><input id="age" type="text" onblur="nianling()" />
                        <span id="spanage" style="color:red"></span>
                    </td>
                </tr>
                <tr>
                    <td>用户状态：</td>
                    <td>
                        <select id="sel">
                            <option value="等待入职">等待入职</option>
                            <option value="在职">在职</option>
                            <option value="兼职">兼职</option>
                            <option value="离职">离职</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>用户角色：</td>
                    <td>
                        <select id="roid">
                            @foreach (var item in ViewBag.zhucelist)
                            {
                                <option value="@item.RoleId">@item.RoleName</option>
                            }
                        </select>
                    </td>
                </tr>
                <tr>
                    <td><input id="Button1" type="button" onclick="quxiao()" value="取消" /></td>
                    <td><input id="Button1" type="button" onclick="tijiao()" value="提交" /></td>
                </tr>
            </table>
        </div>
    </div>
</body>
</html>
<script>
    function quxiao() {
        location.href = "/Home/showUser";
    }
    //用户名非空验证
    function yonghus()
    {
        var n = $("#yonghu").val();
        if (n.length == 0) {
            $("#spanyonghu").html("姓名不能为空哦。");
        }
        else {
            $("#spanyonghu").html("输入正确。");
        }
    }
    //邮箱验证
    function email() {
        var e = $("#youxiang").val();
        if (e.length == 0) {
            $("#spanadd").html("邮箱地址不可以为空哦！");
        }
        else {
            var etest = /^[a-zA-Z0-9_-]+@@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;

            if (!etest.test(e)) {
                $("#spanadd").html("请输入正确的邮箱！");
            }
            else {
                $("#spanadd").html("输入正确。");

            }
        }
    }
    //密码验证
    function pass() {
        var p = $("#mima").val();
        if (p.length == 0) {
            $("#spanpass").html("密码不能为空！");
        }
        else {
            var ptest = /^[a-zA-Z]\w{5,17}$/;
            if (!ptest.test(p)) {
                $("#spanpass").html("以字母开头，长度在6-18之间，只能包含字符、数字和下划线");
            }
            else {
                $("#spanpass").html("格式正确，请进行下一步。");
            }
        }
    }
    //确认密码
    function pass2() {
        var p = $("#mima").val();
        var p2 = $("#tmima").val();
        if (p2.length == 0) {
            $("#spantwo").html("请确认密码！");
        }
        else {
            if (p != p2) {
                $("#spantwo").html("两次密码不一致，请重新输入。");
            }
            else {
                $("#spantwo").html("密码一致，可以通过。");
            }
        }
    }
    //手机验证
    function phone() {
        var p = $("#shouji").val();
        if (p.length == 0) {
            $("#spanphone").html("手机号不能为空。");
        }
        else {
            var ptest = /^1[3,5,7,8]\d{9}$/;
            if (!ptest.test(p)) {
                $("#spanphone").html("请输入正确的大陆手机号。");
            }
            else {
                $("#spanphone").html("输入正确。");
            }
        }
    }
    //姓名验证
    function mingzi() {
        var n = $("#name").val();
        if (n.length == 0) {
            $("#spanname").html("姓名不能为空哦。");
        }
        else {
            $("#spanname").html("输入正确。");
        }
    }
    //年龄验证
    function nianling()
    {
        var age = $("#age").val();
        var agetest = /^(1[89])|([2-7][0-9])|(80)$/;
        if (age.length == 0) {
            $("#spanage").html("请输入该用户的年龄。");
        }
        else {
            if (!agetest.test(age)) {
                $("#spanage").html("请输入正确的年龄。");
            }
            else {
                $("#spanage").html("输入正确。");


            }
        }
    }
    function tijiao() {
        var name = $("#yonghu").val();
        var pass = $("#mima").val();
        var phone = $("#shouji").val();
        var email = $("#youxiang").val();
        var realname = $("#name").val();
        var sex = $("[name='sex']:checked").val();
        var age = $("#age").val();
        var sel = $("#sel").val();
        var roid = $("#roid").val();

        if (name.length == 0) {
            $("#spanyonghu").html("姓名不能为空哦。");
        }
        else {
            $("#spanyonghu").html("输入正确。");
            var p = $("#mima").val();
            if (p.length == 0) {
                $("#spanpass").html("密码不能为空！");
            }
            else {
                var ptest = /^[a-zA-Z]\w{5,17}$/;
                if (!ptest.test(p)) {
                    $("#spanpass").html("以字母开头，长度在6-18之间，只能包含字符、数字和下划线");
                }
                else {
                    $("#spanpass").html("格式正确，请进行下一步。");

                    var p = $("#shouji").val();
                    if (p.length == 0) {
                        $("#spanphone").html("手机号不能为空。");
                    }
                    else {
                        var ptest = /^1[3,5,7,8]\d{9}$/;
                        if (!ptest.test(p)) {
                            $("#spanphone").html("请输入正确的大陆手机号。");
                        }
                        else {
                            $("#spanphone").html("输入正确。");

                            var e = $("#youxiang").val();
                            if (e.length == 0) {
                                $("#spanadd").html("邮箱地址不可以为空哦！");
                            }
                            else {
                                var etest = /^[a-zA-Z0-9_-]+@@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;

                                if (!etest.test(e)) {
                                    $("#spanadd").html("请输入正确的邮箱！");
                                }
                                else {
                                    $("#spanadd").html("输入正确。");

                                    var n = $("#name").val();
                                    if (n.length == 0) {
                                        $("#spanname").html("姓名不能为空哦。");
                                    }
                                    else {
                                        $("#spanname").html("输入正确。");

                                        var age = $("#age").val();
                                        var agetest = /^(1[89])|([2-7][0-9])|(80)$/;
                                        if (age.length == 0) {
                                            $("#spanage").html("请输入该用户的年龄。");
                                        }
                                        else {
                                            if (!agetest.test(age)) {
                                                $("#spanage").html("请输入正确的年龄。");
                                            }
                                            else {
                                                $("#spanage").html("输入正确。");

                                                $.ajax({
                                                    url: "/Home/AddUser",
                                                    type: "post",
                                                    data: { userName: name, userPass: pass, userPhone: phone, userEmail: email, userRealname: realname, userSex: sex, userAge: age, userState: sel, RoleId: roid,userDel:0 },
                                                    success: function (obj) {
                                                        if (obj > 0) {
                                                            location.href = "/Home/Index";
                                                        }
                                                        else {
                                                            alert("注册失败，请检查网络！");
                                                            location.href = "/Home/zhuce";
                                                        }
                                                    }
                                                })
                                            }
                                        }

                                    }

                                }
                            }
                        }
                    }
                }
            }


        }


    }


</script>
